package beanstao.util.threadpool;

import java.util.List;

import beanstao.util.log.ILog;
import beanstao.util.log.LogHelper;

import com.google.common.collect.Lists;

public abstract class AbstractWorkItem<T> implements Runnable, ILog
{
	private final List<T> _ItemList = Lists.newArrayList();

	public void setParms(T... items)
	{
		if ((items != null) && (items.length > 0))
			for (T t : items)
				_ItemList.add(t);
	}

	@Override
	public void run()
	{
		for (T item : _ItemList)
			try
			{
				this.process(item);
			}
			catch (Exception e)
			{
				this.logWarn("工作站的工作项执行过程发生异常。该项跳过。" + item.getClass().getSimpleName() + ". > " + e.getMessage());
			}
	}

	protected abstract void process(T item);

	// ================================

	@Override
	public void logDebug(final Object message)
	{
		LogHelper.logDebug(this, message);
	}

	@Override
	public void logDebug(final Object message, final Throwable t)
	{
		LogHelper.logDebug(this, message, t);
	}

	@Override
	public void logError(final Object message)
	{
		LogHelper.logError(this, message);
	}

	@Override
	public void logError(final Object message, final Throwable t)
	{
		LogHelper.logError(this, message, t);
	}

	@Override
	public void logInfo(final Object message)
	{
		LogHelper.logInfo(this, message);
	}

	@Override
	public void logInfo(final Object message, final Throwable t)
	{
		LogHelper.logInfo(this, message, t);
	}

	@Override
	public void logWarn(final Object message)
	{
		LogHelper.logWarn(this, message);
	}

	@Override
	public void logWarn(final Object message, final Throwable t)
	{
		LogHelper.logWarn(this, message, t);
	}

}
